<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>结题评审意见（科研管理部门）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .mbox {
        padding: 8px
    }
    .item img {
        height: 40px;
    }
    .btn {
        height: 37px;
    }
    .btn button {
        float: right;
    }
    .openFile input[type=file] {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }
    .typeIpt {
        line-height: 30px;
        margin-left: 10px;
    }
    .layui-form-label {
        width: 100px;
    }
    .operationDiv{
        position: absolute;
        width: auto;
        border: #ccc 1px solid;
        border-radius: 4px;
        background-color: #ffffff;
        z-index: 99;
    }
    .operationDiv span{
        cursor: pointer;
        display: block;
        /*width: auto;*/
        height: 20px;
        padding: 5px 0;
        line-height: 20px;
        font-size: 16px;
        text-align: center;
    }
    .operationDiv span:hover{
        background-color: green;
        color: #fff;
    }
</style>
<body>
<div class="mbox">
    <div class="item">
        <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;">
        <span style="font-size: 22px;display: inline-block;vertical-align: middle;">结题评审意见（科研管理部门）</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn" style="display: inline-flex;">
        <span class="typeIpt layui-form">
            <input type="radio" checked class="approve" lay-filter="status" value="1" name="status" title="未上传"/>&nbsp;
            <input type="radio" lay-filter="status" value="2" name="status" title="已上传"/>&nbsp;
            <input type="radio" lay-filter="status" value="3" name="status" title="待批"/>&nbsp;
            <input type="radio" lay-filter="status" value="4" name="status" title="已批"/>&nbsp;
            <input type="radio" lay-filter="status" value="5" name="status" title="未批准"/>&nbsp;
        </span>
    </div>
    <div class="btn">
        <button type="button" class="layui-btn layui-btn-sm" style="background: #2b7fe0">
            <i class="layui-icon layui-icon-upload-drag" style="background: #2b7fe0"></i>导出Excel
        </button>
        <button id="subBtn" type="button" class="layui-btn layui-btn-sm" style="background: #2b7fe0;margin-right: 20px; display: none">
            <i class="layui-icon layui-icon-addition"  style="vertical-align: inherit"></i>批量审批
        </button>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="score">上传意见</a>
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
</script>
<script>
    layui.use(['table', 'form', 'layer', 'laydate', 'upload', ], function () {
        var table = layui.table,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            upload = layui.upload;

        form.render();

        var tableData = table.render({
            elem: '#test'
            , url: '/conclusion_review_commentKy/getReviewCommentKyData'
            , where: {
                trType: 26
                , pageType: 1
            }
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['']
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'topicName', title: '项目名称'}
                , {field: 'planName', title: '申报计划名称'}
                , {field: 'trOther2', title: '学段评分'}
                , {field: 'reviewFraction', title: '专家平均分'}
                , {field: 'zongfen', title: '总分', align: 'center'}
                , {field: 'dengji', title: '等级'}
                , {field: 'trOther5', title: '课题组意见'}
                , {field: 'trOther9', title: '科研管理部门意见',templet:
                        function (d) {
                            if(d.trOther9 == 1 || d.trOther9 == "1"){
                                var str = "同意"
                            }else if(d.trOther9 == 2 || d.trOther9 == "2"){
                                var str = "不同意"
                            } else {
                                var str = ""
                            }
                            return str;
                        }}
                , {field: 'names', title: '项目成员'}
                , {field: 'headUserName', title: '负责人'}
                , {field: 'type', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true
        });

        // 页签转换
        form.on('radio(status)', function (data) {
            switch (data.value) {
                case "1":   // 未上传数据
                    $("#subBtn").css("display", "none");
                    tableData.reload({
                        where: {
                            trType: 26
                            , pageType: 1
                        }
                    });
                    break;
                case "2":   // 已上传数据
                    $("#subBtn").css("display", "none");
                    tableData.reload({
                        where: {
                            trType: 26
                            , pageType: 2
                        }
                    });
                    break;
                case "3":   // 待批
                    $("#subBtn").css("display", "block");
                    tableData.reload({
                        where: {
                            trType: 26
                            , trStatus: 1
                            , pageType: 3
                        }
                    });
                    break;
                case "4":   // 已批
                    $("#subBtn").css("display", "none");
                    noBtnTable(26, 2, 4);
                    break;
                case "5":   // 未批
                    $("#subBtn").css("display", "none");
                    noBtnTable(26, 3, 5);
                    break;
            }
        });

        // 无工具栏表格
        function noBtnTable(trType, trStatus, pageType) {
            noDataTable = table.render({
                elem: '#test'
                , url: '/conclusion_review_commentKy/getReviewCommentKyData'
                , where: {
                    trType: trType
                    , trStatus: trStatus
                    , pageType: pageType
                }
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , defaultToolbar: ['']
                , title: '用户数据表'
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'topicName', title: '项目名称'}
                    , {field: 'planName', title: '申报计划名称'}
                    , {field: 'trOther2', title: '学段评分'}
                    , {field: 'reviewFraction', title: '专家平均分'}
                    , {field: 'zongfen', title: '总分', align: 'center'}
                    , {field: 'dengji', title: '等级'}
                    , {field: 'trOther5', title: '课题组意见'}
                    , {field: 'trOther9', title: '科研管理部门意见',templet:
                            function (d) {
                                if(d.trOther9 == 1 || d.trOther9 == "1"){
                                    var str = "同意"
                                }else if(d.trOther9 == 2 || d.trOther9 == "2"){
                                    var str = "不同意"
                                }else {
                                    var str = ""
                                }
                                return str;
                            }}
                    , {field: 'names', title: '项目成员'}
                    , {field: 'headUserName', title: '负责人'}
                ]]
                , page: true
            });
        }

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            var fil = empty(data.trOther6);
            if(fil == "" || fil == undefined || fil == "undefind"){
                var aName = "";
                var aId = "";
            }else{
                var aName = fil.split(",")[1];
                var aId = fil.split(",")[0];
            }
            if(obj.event === 'score'){
                layer.open({
                    type: 1,
                    title: '上传意见',
                    btn: ['确定', '取消'],
                    shade: 0.5,
                    area: ['50%', '50%'],
                    content:'<div id="cont" style="margin: 10px">\n' +
                        '        <form class="layui-form" action="" id="ajaxforms" lay-filter="ajaxforms">\n' +
                        '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                        '                <div class="layui-inline">\n' +
                        '                   <label class="layui-form-label" style="width: 126px;">课题组意见(申报人):</label>\n' +
                        '                    <div class="layui-input-inline">\n' +
                        '                        <input id="trother8" type="text" name="trOther8" lay-verify="required|phone" autocomplete="off"\n' +
                        '                               class="layui-input required">\n' +
                        '                    </div>\n' +
                        '                </div>\n' +
                        '            </div>\n' +
                        '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                        '                   <label class="layui-form-label" style="margin-left: 30px;">选项:</label>\n' +
                        '                   <div class="layui-input-block" id="radioBox">\n' +
                        '                       <input type="radio" name="state" value="1" title="同意" checked="">\n' +
                        '                       <input type="radio" name="state" value="2" title="不同意">\n' +
                        '                    </div>\n' +
                        '            </div>\n' +
                        '        </form>\n' +
                        '    </div>',
                    success: function () {
                        $("#trother8").val(data.trOther8);
                        var num = data.trOther9;
                        if(num == "1" || num == 1){
                            $("#radioBox").find("input").eq(0).attr("checked",true);
                        }else if(num == "2" || num == 2){
                            $("#radioBox").find("input").eq(1).attr("checked",true);
                        }
                        form.render();
                    },
                    yes:function (index) {
                        var trOther8 = $('input[name="trOther8"]').val();
                        var trOther9 = $('input[name="state"]:checked').val();
                        var trId = data.trId;
                        if (trOther8 == null || trOther8 == undefined) {
                            layer.msg("请填写课题组意见", {time: 1500, icon: 7});
                        } else {
                            $.ajax({
                                url: '/conclusion_review_commentKt/uploadOpinion'
                                , type: 'post'
                                , data: {
                                    trId: trId
                                    , trOther8: trOther8
                                    , trOther9: trOther9
                                }
                                , dataType: 'json'
                                , success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg("上传成功", {time: 1500, icon: 1});
                                        // 获取当前页签的值
                                        var pageType = $('input[name="status"]:checked').val()
                                        if (pageType == 1) {
                                            tableData.reload({
                                                where: {
                                                    trType: 26
                                                    , pageType: 1
                                                }
                                            });
                                        }else if (pageType == 2) {
                                            tableData.reload({
                                                where: {
                                                    trType: 26
                                                    , pageType: 2
                                                }
                                            });
                                        } else if (pageType == 3) {
                                            // 刷新表格
                                            tableData.reload({
                                                where: {
                                                    trType: 26
                                                    , trStatus: 1
                                                    , pageType: 3
                                                }
                                            });
                                        } else if (pageType == 4) {
                                            noBtnTable(26, 2, 4);
                                        } else if (pageType == 5) {
                                            noBtnTable(26, 3, 5);
                                        }
                                    } else {
                                        layer.msg("上传失败", {time: 1500, icon: 2});
                                    }
                                }
                            });
                        }
                        layer.close(index);
                    }
                })
            }
            if(obj.event === 'look'){
                layer.open({
                    type: 1,
                    title: '上传评分',
                    btn: ['确定', '取消'],
                    shade: 0.5,
                    area: ['600px', '70%'],
                    content: '<div id="cont" style="margin: 10px">\n' +
                    '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '                <div class="layui-inline">\n' +
                    '                   <span style="color:red">*</span><label class="layui-form-label">项目名称:</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="planName" disabled lay-verify="required|phone" value="'+empty(data.topicName)+'" autocomplete="off"\n' +
                    '                               class="layui-input required">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '                <div class="layui-inline">\n' +
                    '                   <span style="color:red">*</span><label class="layui-form-label">申报计划:</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="planName" disabled lay-verify="required|phone" autocomplete="off"\n' +
                    '                               class="layui-input required" value="'+empty(data.planName)+'">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    ' <div class="layui-inline share">\n' +
                    '                    <label class="layui-form-label">负责人:</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" id="rescueUser" user_id="" value="'+empty(data.headUserName)+'" lay-verify="url" autocomplete="off" class="layui-input" disabled style="width: 192px">\n' +
                    '                    </div>\n' +
                    '                </div>'+
                    ' <div class="layui-form-item"  style="margin-top:15px">\n' +
                    '    <label class="layui-form-label" style="width: 100px;">学段意见:</label>\n' +
                    '    <div class="layui-input-inline" id="yj" style="width: 300px;padding: 9px 0;">' +
                    '        <div onmouseenter="shover($(this))" onmouseleave="sover($(this))"><span  style="color:green;cursor: pointer;width: 100%;display: inline-block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;" attachName="' + aName + '" attachId="' + aId + '"  class="layui-table-link aUploadFile giv">' + "【" + aName + "】" + '</span><div class="operationDiv" style="display: none;"><span href="javascript:;" class="spanNa" style="cursor: pointer;"></span><span class="" attachName="' + aName + '" attachId="' + aId + '" onclick="down($(this))" >下载</span></div></div><br style="line-height: 1px;">'+
                    '</div>' +
                    '</div>' +
                    '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '                <div class="layui-inline">\n' +
                    '                   <span style="color:red">*</span><label class="layui-form-label">学段评分:</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="trOther2" disabled lay-verify="required|phone" autocomplete="off"\n' +
                    '                               class="layui-input required"  value="'+empty(data.trOther2)+'">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '            <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '                <div class="layui-inline">\n' +
                    '                   <span style="color:red">*</span><label class="layui-form-label">专家平均分:</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="planName" disabled lay-verify="required|phone" autocomplete="off"\n' +
                    '                               class="layui-input required" value="'+empty(data.reviewFraction)+'">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '            </div>\n'+
                    '        </form>\n' +
                    '    </div>',
                    success: function () {
                        if(fil == "" || fil == undefined || fil == "undefind"){
                            $("#yj").html("");
                        }
                        //附件上传
                        form.render();
                    },
                    yes:function (index) {
                        layer.close(index);
                    }
                });
            }
        });

        // 批量审批按钮点击事件
        $('#subBtn').click(function () {
            //获取表格选中数据
            var checkData = layui.table.checkStatus('test').data;
            if (checkData.length > 0) {
                var trIds = "";
                for (var i = 0; i < checkData.length; i++) {
                    trIds += checkData[i].trId + ",";
                }
                open(trIds);
            } else {
                layer.msg("请选择需要审批的数据", {time: 1500, icon: 7});
            }
        });

        // 审批弹出层
        function open(trIds) {
            layer.open({
                type: 1,
                title: '审批',
                btn: ['确定', '取消'],
                area: ['20%', '30%'],
                content: '<div class="layui-form" style="width: 70%;margin: 15px auto">' +
                    '<div class="layui-form-item">' +
                    ' <input type="radio" name="trStatus" value="2" title="同意" checked>' +
                    ' <input type="radio" name="trStatus" value="3" title="不同意">' +
                    '    </div>' +
                    '</div>',
                success: function () {
                    form.render('radio')
                },
                yes: function (index) {
                    var trStatus = $('[name="trStatus"]:checked').val()
                    if (trStatus == 2) {    // 审批通过
                        failed(trIds, 2);
                    } else if (trStatus == 3) { // 审批未通过
                        failed(trIds, 3);
                    }
                    layer.close(index);
                }
            });
        }

        // 不审批方法
        function failed(trIds, newTrStatus) {
            $.ajax({
                url: '/conclusion_review_commentKt/notApproved'
                , type: 'post'
                , data: {
                    trIds: trIds
                    , newTrStatus: newTrStatus
                }
                , dataType: 'json'
                , async: false
                , success: function (res) {
                    if (res.code == 0) {
                        layer.msg("审批完成", {time: 1500, icon: 1});
                    } else {
                        layer.msg("审批失败", {time: 1500, icon: 2});
                    }
                    tableData.reload();
                }
            });
        }
    });
    //判断空的方法
    function empty(name){
        if(name==undefined||name==''){
            return ''
        }else{
            return name
        }
    }
    // 鼠标移入
    function shover(e) {
        e.find(".operationDiv").css("display","block");
        e.find("span.spanNa").html(e.find(".giv").html());
    }
    // 鼠标移出
    function sover(e) {
        e.find(".operationDiv").css("display","none");
    }
    // 下载
    function down(e) {
        var attachid = e.parents(".operationDiv").prev("span.giv").attr("attachid");
        if(attachid == undefined || attachid=='' || attachid == "undefined"){
            layer.msg("文件损坏或未上传附件")
        }else{
            window.location.href = "/equipment/limsDownload?model=conclusion&attachId=" +attachid
        }
    }
</script>
